/**
 * @Author: Nick Zhang <thesadboy@vip.qq.com>
 * @Description: 编辑器监听器，主要处理打开文件后的逻辑
 * @Date: 2024-06-12 10:16:24
 * @LastEditors: Nick Zhang <thesadboy@vip.qq.com>
 * @LastEditTime: 2024-07-03 11:25:17
 */
package com.nickzhang.jetbrains.file_description_plugin.listeners

import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.intellij.openapi.vfs.VirtualFile
import com.nickzhang.jetbrains.file_description_plugin.configs.AppSettingState
import com.nickzhang.jetbrains.file_description_plugin.utils.CommentUtil
import com.nickzhang.jetbrains.file_description_plugin.utils.CommonUtil

internal class AppFileEditorManagerListener : FileEditorManagerListener {
    override fun fileOpened(source: FileEditorManager, file: VirtualFile) {
        val state: AppSettingState = AppSettingState.getInstance()
        if (!state.openFileCheck || CommonUtil.checkIsFileIsIgnored(file)) return
        val document = FileDocumentManager.getInstance().getDocument(file)
        document?.let { CommentUtil.checkAddCommentHeader(it, file) }
    }
}
